#include <iostream>
#include <time.h>
using namespace std;
#include "WeaponGenerator.h"

Weapon::Weapon()
{
	wg_prefix1_s =				"";
	wg_prefix2_s =				"";
	wg_weaponname =				"Item";
	wg_weaponclass_s=			"Brawl";
	string wg_weapontype_s=		"Unknown";

	wg_stun_i		= 0;
	wg_energy_i		= 0;
	wg_pierce_i		= 0;
	wg_basedmg_i	= 0;
	wg_armor_i		= 0;

	wg_weight_f	= 2;
	wg_durability_f	= 20;
}

void Weapon::CalculateWeaponType()
{			
	wg_weapontype_s = "Custom";

	if(wg_pierce_i == wg_basedmg_i)						
	{wg_weapontype_s = "Pierce";}
	
	if(wg_stun_i == wg_basedmg_i)
	{wg_weapontype_s = "Stun";}

	if(wg_energy_i == wg_basedmg_i)
	{wg_weapontype_s = "Energy";}
	
	if(wg_pierce_i > wg_basedmg_i )
	{wg_weapontype_s = "Pierce+";}
	
	if(wg_stun_i > wg_basedmg_i )
	{wg_weapontype_s = "Stun+";}

	if(wg_energy_i > wg_basedmg_i)
	{wg_weapontype_s = "Energy+";}
	
	if(wg_stun_i == wg_basedmg_i && wg_armor_i > 0)
	{wg_weapontype_s = "Protect";}

	if(wg_stun_i == wg_pierce_i && wg_basedmg_i > 0 && wg_energy_i < wg_pierce_i)
	{wg_weapontype_s = "Balance";}
	
	cout << wg_weapontype_s << endl;
}

void Weapon::GenerateRandomBrawl()
{
	GenerateSpread();
	//Spends the spread as determined by the weapontype
	//If a weapontype isn't determined, it's randomised.
	//Generate a good name for it afterwords
}
void Weapon::GenerateRandomStomp()
{
	GenerateSpread();
	//Spends the spread as determined by the weapontype
	//If a weapontype isn't determined, it's randomised.
	//Generate a good name for it afterwords
}
void Weapon::GenerateRandomWeaponry()
{
	GenerateSpread();
	//Spends the spread as determined by the weapontype
	//If a weapontype isn't determined, it's randomised.
	//Generate a good name for it afterwords
}
void Weapon::GenerateRandomPrecision()
{
	GenerateSpread();
	//Spends the spread as determined by the weapontype
	//If a weapontype isn't determined, it's randomised.
	//Generate a good name for it afterwords
}

void Weapon::GenerateSpread()
{
	int Spread;
	int Choice;

	cout << "What would you like the spread of the weapon to be: ";
	cin  >> Spread;

	while(Spread %5 != 0){cout << "Must be divisible by 5. Choose Again: ";cin>>Spread;}
	//Makes sure it's a valid spread

	system("cls");
	cout << "Choose a weapon type.\n\n";
	cout << "1: Pierce\n";
	cout << "2: Pierce+\n";
	cout << "3: Stun\n";
	cout << "4: Stun+\n";
	cout << "5: Energy\n";
	cout << "6: Energy+\n";
	cout << "7: Protect\n";
	cout << "8: Balance\n";
	cout << "9: Random\n";
	cin  >> Choice;

	while(Choice < 1 && Choice > 9){cout << "Improper Input. Choose Again: ";cin>>Choice;}
	//Makes sure it's a valid Choice

	if(Choice == 9)
	{srand ( time(NULL) );Choice = rand() % 7 + 1;}
	//Randomises a value if 9 is chosen

	if(Choice == 2 || Choice == 4 || Choice == 6)
	{if(Spread %10 == 0){cout << "Must be an odd number. Forcing Change..\n";Choice--;}}
	////Can't have a + weapon if the spread is even

	if(Choice == 1 || Choice == 3 || Choice == 5)
	{if(Spread %10 != 0){cout << "Must be an even number. Forcing Change.\n";Choice++;}}
	////Can't have a normal weapon if the spread is odd
  
	switch(Choice)
	{
		/*/////PIERCE BEGIN /////*/
		case 1:
			wg_pierce_i = Spread/2;
			wg_basedmg_i = Spread/2;
			break;
		case 2:
			while(Spread > 0)
			{
				wg_pierce_i +=5;
				Spread -=5;	
				if(Spread > 0)
				{
					wg_basedmg_i +=5;
					Spread -=5;
				}
			}
			break;
		/*/////STUN BEGIN /////*/
		case 3:
			wg_stun_i = Spread/2;
			wg_basedmg_i = Spread/2;
			break;
		case 4:
			while(Spread > 0)
			{
				wg_stun_i += 5;
				Spread -=5;
				if(Spread > 0)
				{
					wg_basedmg_i +=5;
					Spread-=5;
				}

			}
			break;
		/*/////ENERGY BEGIN /////*/
		case 5:
			wg_energy_i = Spread/2;
			wg_basedmg_i = Spread/2;
			break;
		case 6:
			while(Spread > 0)
			{
				wg_energy_i += 5;
				Spread -=5;
				if(Spread > 0)
				{
					wg_basedmg_i +=5;
					Spread-=5;
				}

			}
			break;
		/*/////PROTECT BEGIN /////*/
		case 7:
			while(Spread > 0)
			{
				if(Spread >= 20)
				{
					wg_stun_i +=10;
					wg_basedmg_i +=10;
					Spread -=20;
				}
				if(Spread >= 10)
				{
					wg_pierce_i += 5;
					wg_armor_i += 5;
					Spread -=10;
				}
				if(Spread >= 5)
				{
					wg_armor_i +=5;
					Spread-=5;
				}
			}
			break;
		/*/////BALANCE BEGIN /////*/
		case 8:
			while(Spread > 0)
			{

				if(Spread >= 10)
				{
					wg_pierce_i +=5;
					wg_stun_i += 5;
					Spread -=10;
				}
				if(Spread >= 5)
				{
					wg_basedmg_i += 5;
					Spread -= 5;
				}
			}
			break;
	}

	cout << endl;
	cout << "The weapon type is ";
	CalculateWeaponType();
	cout << "Pierce: " << wg_pierce_i  << endl;
	cout << "Stun: "   << wg_stun_i << endl;
	cout << "Energy: " << wg_energy_i << endl;
	cout << "Damage: " << wg_basedmg_i << endl;
	cout << "Armor: " << wg_armor_i << endl;

}